package us.gaaoc.framework.webapp.backingbeans.admin;

import java.util.List;
import java.util.Map;

import javax.faces.component.UIParameter;
import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import us.gaaoc.framework.businessmodel.Filing;
import us.gaaoc.framework.webapp.backingbeans.BaseBackingBean;

/**
 * 
 * @author hea
 * @date Apr 21, 2006
 * @version: GAJE 1.5
 *
 */
public class TransmissionErrorFilingPage extends BaseBackingBean {
	
	/**
	 * Properties
	 */
	private DataModel errorFilingDataTable;
	private UIParameter caseDetailsPageClicked;
	private Filing filing;

	/**
	 * Constructor
	 *
	 */
	public TransmissionErrorFilingPage(){
		errorFilingDataTable = new ListDataModel();
		List errorFilings = this.getModelFacade().findErrorFilings();
		errorFilingDataTable.setWrappedData(errorFilings);
	}
	
	/**
	 * @return Returns the filing.
	 */
	protected Filing getFiling() {
		return filing;
	}

	/**
	 * @param filing The filing to set.
	 */
	protected void setFiling(Filing filing) {
		this.filing = filing;
	}

	/**
	 * Getter for property errorFilingDataTable
	 * @return errorFilingDataTable
	 */
	public DataModel getErrorFilingDataTable() {
		return errorFilingDataTable;
	}

	/**
	 * Setter for property errorFilingDataTable
	 * @param errorFilingDataTable
	 */
	public void setErrorFilingDataTable(DataModel errorFilingDataTable) {
		this.errorFilingDataTable = errorFilingDataTable;
	}

	/**
	 * @return Returns the caseDetailsPageClicked.
	 */
	public UIParameter getCaseDetailsPageClicked() {
		return caseDetailsPageClicked;
	}

	/**
	 * @param caseDetailsPageClicked The caseDetailsPageClicked to set.
	 */
	public void setCaseDetailsPageClicked(UIParameter caseDetailsPageClicked) {
		this.caseDetailsPageClicked = caseDetailsPageClicked;
	}
	
	/**
	 * This method navigates user to the case Details Page
	 * @return String
	 */
	@SuppressWarnings("unchecked")
	public String gotoCaseDetailPage() {
		Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
		this.filing = (Filing)this.getCaseDetailsPageClicked().getValue();
	 	String caseUuid = filing.getUuid();
	 	String caseType = filing.getCaseType();
	 	String toString="";
	 	if(caseType.equals("ChildSupportEnforcement"))
	 		toString = "gotoCSECaseDetailsPage";
	 	else toString = "gotoCaseDetailsPage";
	 	
	 	sessionMap.put("caseUuid", caseUuid);
	 	sessionMap.put("from", "TransmissionErrorFilingPage");
	 				
		return toString;
	}

	/**
	 * This method clears the case record from the list and puts in the trash can
	 * @return String
	 */
	public String clear(){
		String courtUuid = (String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("courtUuid");
	 	Map requestMap = this.getFacesContext().getExternalContext().getRequestParameterMap();
	 	String caseUuid = ((String) requestMap.get("caseUuid"));
	 	this.getModelFacade().updateCaseRecordForClearCase(caseUuid, true, courtUuid);
	 	//HibernatePhaseListener.getSessionFactory().getCurrentSession().getTransaction().commit();
	  	return "stay";
	}

	/**
	 * This method navigates user to the previous page
	 * @return String
	 */
	public String back(){
		return "back";
	}

	/**
	 * This method navigates user to the history page
	 * @return String
	 */
	public String gotoHistoryPage() {
		Map sessionMap = this.getFacesContext().getExternalContext()
				.getSessionMap();
		Map requestMap = this.getFacesContext().getExternalContext()
				.getRequestParameterMap();
		String caseUuid = ((String) requestMap.get("caseUuid"));
		sessionMap.put("caseUuid", caseUuid);
		sessionMap.put("from", "TransmissionErrorFilingPage");
		return "gotoCaseHistoryPage";
	}
}
